#include "comfunc.h"

void printf_arr(quint8 *data, int len, quint8 base_num )
{

    while(len--)
    {
        if(10 == base_num)
        {
            printf("%d ",*(data++));
        }
        if(16 == base_num)
        {
            printf("%02X ",*(data++));
        }
    }
    printf("\n");
}

uint16_t sp_crc16_with_init(uint16_t crc, const uint8_t *buf, uint16_t size)
{
    unsigned char i;

    while (size-- != 0)
    {
        for (i = 0x80; i != 0; i >>= 1)
        {
            if ((crc & 0x8000) != 0)
            {
                crc <<= 1;
                crc ^= 0x1021;
            }
            else
            {
                crc <<= 1;
            }
            if (((*buf) & i) != 0)
            {
                crc ^= 0x1021;
            }
        }
        buf++;
    }
    return (crc);
}
